/**
 * May 23, 2014 3:42:50 PM
 */
package elitech.vietnam.copyweatherfashion.dialog;

import elitech.vietnam.copyweatherfashion.R;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

/**
 * @author Cong
 *
 */
public class EditDialogFragment extends DialogFragment implements View.OnClickListener {

	ImageButton		mBtnEdit, mBtnDelete;
	ActionSelectListener mListener;
	
	public static EditDialogFragment newInstance() {
		EditDialogFragment fragment = new EditDialogFragment();
		fragment.setStyle(STYLE_NO_TITLE, R.style.Dialog);
		return fragment;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		try {
			mListener = (ActionSelectListener) getActivity();
		} catch (ClassCastException e) {
			throw new ClassCastException("Host activity must implement ActionSelectListener");
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.dialog_editpost, container, false);

		mBtnEdit = (ImageButton) view.findViewById(R.id.editpost_btnEdit);
		mBtnDelete = (ImageButton) view.findViewById(R.id.editpost_btnDelete);

		mBtnEdit.setOnClickListener(this);
		mBtnDelete.setOnClickListener(this);

		return view;
	}

	/**
	 * @deprecated: should use {@link #show(FragmentManager)} method instead
	 */
	@Deprecated
	@Override
	public void show(FragmentManager manager, String tag) {
		super.show(manager, tag);
	}
	
	public void show(FragmentManager manager) {
		super.show(manager, getClass().getName());
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.editpost_btnEdit:
			if (mListener != null)
				mListener.edit();
			break;
		case R.id.editpost_btnDelete:
			if (mListener != null)
				mListener.delete();
			break;
		default:
			break;
		}
		dismiss();
	}

	public interface ActionSelectListener {
		public void edit();
		public void delete();
	}
}
